/* LAFDemo.java 
* Created on Dec 15, 2012 
*@Author: Mr.Viet 
*@Phone: 01683430426 
*@Email: phamvanvietcdhd@gmail.com
*/ 
package com.session13; 

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.jvnet.substance.skin.SubstanceAutumnLookAndFeel;
import org.jvnet.substance.skin.SubstanceChallengerDeepLookAndFeel;
import org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel;

public class LAFDemo extends JFrame implements ChangeListener {
	private JMenuBar mbar;
	private JMenu mFile,mEdit,mLaf;
	private JMenuItem mnOpen,mnSave,mnSize;
	private JRadioButtonMenuItem mnLaf1,mnLaf2;
	public LAFDemo() {
	}
	public void createForm(){
		this.mbar = new JMenuBar();
		this.mFile = new JMenu("File");
		this.mEdit = new JMenu("Edit");
		this.mLaf = new JMenu("Look And feel...");
		this.mnOpen = new JMenuItem("Open ...");
		this.mnSave = new JMenuItem("Save As...");
		this.mnSize = new JMenuItem("Size");
		
		this.mnLaf1 = new JRadioButtonMenuItem("Skin 1");
		this.mnLaf2 = new JRadioButtonMenuItem("Skin 2");
		ButtonGroup g = new ButtonGroup();
		g.add(mnLaf1);
		g.add(mnLaf2);
		
		this.mFile.add(this.mnOpen);
		this.mFile.add(this.mnSave);
		this.mFile.add(this.mnSize);
		
		this.mLaf.add(this.mnLaf1);
		this.mLaf.add(this.mnLaf2);
		
		this.mbar.add(this.mFile);
		this.mbar.add(this.mEdit);
		this.mbar.add(this.mLaf);
		
		this.setJMenuBar(this.mbar);
		//Dang Ki Su Kien
		this.mnLaf1.addChangeListener(this);
		this.mnLaf2.addChangeListener(this);
	}
	
	public void showForm(){
		this.setTitle("Home App");
		this.setExtendedState(JFrame.MAXIMIZED_BOTH);
		this.setLocationRelativeTo(null);//set ra giua
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}
	
	public static void main(String[] args) {
		JFrame.setDefaultLookAndFeelDecorated(true);
		SwingUtilities.invokeLater(new Runnable() {
			
			@Override
			public void run() {
				try {
					UIManager.setLookAndFeel(new SubstanceAutumnLookAndFeel());
				} catch (UnsupportedLookAndFeelException e) {
					e.printStackTrace();
				}
				LAFDemo l =  new LAFDemo();
				l.createForm();
				l.showForm();
			}
		});
		
	}
	@Override
	public void stateChanged(ChangeEvent e) {
		if(e.getSource() == this.mnLaf1){
			SwingUtilities.invokeLater(new Runnable(){

				@Override
				public void run() {
					try {
						UIManager.setLookAndFeel(new SubstanceChallengerDeepLookAndFeel());
					} catch (UnsupportedLookAndFeelException e1) {
						e1.printStackTrace();
					}
				}});
			
		}
		if(e.getSource() == this.mnLaf2){
			try {
				UIManager.setLookAndFeel(new SubstanceOfficeBlue2007LookAndFeel());
			} catch (UnsupportedLookAndFeelException e1) {
				e1.printStackTrace();
			}
		}
	}

}
